using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;

namespace SharpWind.Gui.Controls
{
	public class ObjectCollection<T> : IEnumerable
	{
		internal event EventHandler ItemAdd = null;

		internal event EventHandler ItemRemove = null;

		private List<T> list = new List<T>();

		public void Add( T item )
		{
			this.list.Add( item );

			if( ItemAdd != null )
			{
				ItemAdd( this, EventArgs.Empty );
			}
		}

		public void RemoveAt( int index )
		{
			this.list.RemoveAt( index );
			if( ItemRemove != null )
			{
				ItemRemove( this, EventArgs.Empty );
			}
		}

		public bool Remove( T item )
		{
			bool result = this.list.Remove( item );
			if( result && ItemRemove != null )
			{
				ItemRemove( this, EventArgs.Empty );
			}

			return result;
		}

		public T[] ToArray()
		{
			return this.list.ToArray();
		}

		public T this[int index]
		{
			get
			{
				return this.list[index];
			}
			set
			{
				this.list[index] = value;
			}
		}

		public int Count
		{
			get
			{
				return this.list.Count;
			}
		}

		public IEnumerator GetEnumerator()
		{
			return this.list.GetEnumerator();
		}
	}
}
